<?php
//-------------------------------------------------------------------------------------------------------
    require_once($config['app_dir'] . '/classes/calcplot.class.php');
    require_once($config['app_dir'] . '/classes/plot.view.php');
    //---------------------------------------------------------------------------------------------------
        class objProfitGraphModel {
            protected $data = false;
            protected $data_x = false;
            protected $data_y = false;
            protected $pepared = false;

        public function ClassName() {
            return  __CLASS__;
        }//ClassName

        public function SetData($aData) {
            $this->data = $aData;
        }//setData

        public function getDataX($force=false){
            if( $force || false===$this->pepared ) $this->Prepare();
            return $this->data_x;
        }//getDataX

        public function getDataY($force=false){
            if( $force || false===$this->pepared ) $this->Prepare();
            return $this->data_y;
        }//getDataY

        public function isEmpty() {
            return empty($this->data) || false===$this->data;
        }//isEmpty

        public function Dump() {
            echo "<pre>";
            echo "\n Damp(" . $this->ClassName() . "): ";
            echo "\n Data: "; var_dump($this->data);
            echo "\n DataX: "; var_dump($this->data_x);
            echo "\n DataY: "; var_dump($this->data_y);
            echo "\n Prepared: "; var_dump($this->pepared);
            echo "</pre>";
        } //Dump

        protected function Prepare() {
            $this->pepared = false;

            $this->data_x = array();
            $this->data_y = array();

            foreach($this->data as $item) {
                $this->data_x[] = $item['pair'];
                $this->data_y[] = $item['value'];//profit
            }//foreach

            $this->pepared = true;

            return $this->pepared;
        }//Prepare

    }//class ProfitGraphModel
    //---------------------------------------------------------------------------------------------------
    class objProfitGraphView extends objPlotView{
            protected $_graph = false;

            public $data_x = array();
            public $data_y = array();

        public function __construct($aWidth, $aHeight) {
            $this->_graph = new Graph($aWidth, $aHeight, 'auto');
        }//constructor

        public function ClassName() {
            return  __CLASS__;
        }//ClassName

        protected function BuildAxisX() {
            $this->_graph->xaxis->SetTickLabels($this->data_x);

            $this->_graph->xaxis->SetFont(FF_VERDANA, FS_NORMAL, 6);
            $this->_graph->xaxis->SetSelectedFont(FF_VERDANA, FS_BOLD, 6);
			$this->_graph->xaxis->SetLabelAngle(50);
			$this->_graph->xaxis->SetLabelMargin(6);

            $this->_graph->xaxis->title->SetFont(FF_VERDANA, FS_BOLD, 6);


            $this->_graph->xgrid->Show(false, false);
			$this->_graph->xaxis->HideTicks(true, true);
            return true;
        }//BuildAxisX

        protected function BuildAxisY() {
            $this->_graph->yaxis->HideTicks(true, false);
            $this->_graph->yaxis->SetFont(FF_VERDANA, FS_NORMAL, 6);
            $this->_graph->yaxis->SetSelectedFont(FF_VERDANA, FS_BOLD, 6);
            $this->_graph->yaxis->title->SetFont(FF_VERDANA, FS_BOLD, 6);
            $this->_graph->yaxis->SetTitle("pips");
            //$this->_graph->yaxis->SetTitleMargin(50);
            //$this->_graph->xaxis->SetTitleSide(SIDE_BOTTOM);

            $this->_graph->yaxis->title->SetAngle(0);
            $this->_graph->yaxis->title->SetAlign('bottom');
            $this->_graph->yaxis->HideFirstLastLabel();
            $this->_graph->ygrid->Show(true, false);

            return true;
        }//BuildAxisY

        public function BuildGraph() {
		  global $config;
            $this->_graph->SetImgFormat(strtoupper($this->type));

            $this->_graph->SetBox(false);
            $this->_graph->SetFrame(false);

            if( $config['jpgraph']['antialiasing'] )  $this->_graph->img->SetAntiAliasing();
            $this->_graph->SetMarginColor('white');
            $this->_graph->SetMargin(30,10,10,43);
            $this->_graph->SetScale("textlin");

            $bplot = new BarPlot($this->data_y);
            $bplot->SetColor('#aaaaaa@0.01');
            $bplot->SetFillColor('#dce6be@0.4',true);
			$bplot->SetValuePos('top');
			$bplot->SetAlign("center");

			$bplot->value->Show();
            $bplot->value->SetFormat('%d');
			$bplot->value->SetFont(FF_VERDANA, FS_NORMAL, 5.7);
            //$bplot->value->SetLabelFormat();
			$bplot->value->SetColor('black','red');
            $this->_graph->Add($bplot);

            $this->BuildAxisX();
            $this->BuildAxisY();

            $this->_graph->Stroke();
        }//BuildGraph

    }//class ProfitGraphView

//-------------------------------------------------------------------------------------------------------
?>
